<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新增的表单事件</title>
</head>
<body>
    <form action="">
        <p>用户名：<input type="text" name="userName" id="userName"></p>
        <p>电话：<input type="tel" name="userPhone" id="userPhone" pattern="^1\d(10)$"></p>
        <p><input type="submit" value="提交"></p>
    </form>
    <script>
        // oninput 监听当前指定元素内容的改变：只要表单元素内容变化（新增、删除）就会触发这个事件
        document.getElementById("userName").oninput = function() {
            console.log("oninput:", this.value)
        }

        // onkeyup 当键盘弹起的时候触发：每一个键的弹起都会触发一次
        document.getElementById("userName").onkeyup = function() {
            console.log("onkeyup:", this.value)
        }

        // oninvalid 当验证不通过时触发 
        document.getElementById("userPhone").oninvalid = function() {
            this.setCustomValidity("请输入合法的手机号码")
        }

    </script>
</body>
</html>